package com.moleq.device.printer;

import java.util.ArrayList;
import java.util.List;

public class PrinterBufferRowColection {

	List<PrinterBufferRow> rows = new ArrayList<PrinterBufferRow>() ;
	
	public void add(PrinterBufferRow obj){

		rows.add(obj);
		
	}
	
	public void clear(){
		rows.clear();
	}
	
	public int count(){
		return rows.size();
	}
	
	public PrinterBufferRow get(int location){
		return rows.get(location);
	}
	
	public PrinterBufferRow Find(Object key){
		
		return null;
	}
	
	public boolean contains(Object key){
		
		return false;
	}
	
	public String toReceipt(){
		String result = "";
		if (rows != null) {
			for (int i = 0; i < rows.size(); i++) {
				result += rows.get(i).getContent(42);
			}
		}
		
		return result ;
	}

	public void addBlankRow() {
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		column.setScale(100);
		column.setContent(" ", Printer.FULL_LINE);
		row.columns.add(column);
		rows.add(row);
	}
	
	public void addNormalRow(String text){
		addNormalRow(text,Printer.FONT_SINGLE_SIZE,Printer.CENTER);
	}
	
	public void addNormalRow(String text,int fontSize,int align){
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		column.setScale(100);
		column.setContent(text);
		column.setFontSize(fontSize);
		column.setAlign(align);
		row.columns.add(column);
		rows.add(row);
	}
	
	public void addFullRow(String singleChar){
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		column.setScale(100);
		column.setContent(singleChar, Printer.FULL_LINE);
		row.columns.add(column);
		rows.add(row);
	}
	
//	public void addMultipleColumn(int columnCount,int align,String...args){
//		PrinterBufferRow row = new PrinterBufferRow();
//		PrinterBufferColumn column = new PrinterBufferColumn();
//		
//		if (columnCount > 0) {
//			double percent = (double)100 / columnCount;
//			for (int i = 0; i < columnCount; i++) {
//				column = new PrinterBufferColumn();
//				column.setScale(percent);
//				column.setContent(args[i]);
//				column.setAlign(align);
//				row.columns.add(column);
//			}
//			rows.add(row);
//		}
//		
//	}
	
	public void addTenderItem(String...args){
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		
		column = new PrinterBufferColumn();
		column.setScale(20);
		row.columns.add(column);
		
		column = new PrinterBufferColumn();
		column.setScale(30);
		column.setContent(args[0]);
		column.setAlign(Printer.RIGHT);
		row.columns.add(column);
		
		column = new PrinterBufferColumn();
		column.setScale(30);
		column.setContent(args[1]);
		column.setAlign(Printer.RIGHT);
		row.columns.add(column);
		
		column = new PrinterBufferColumn();
		column.setScale(20);
		row.columns.add(column);
	
		rows.add(row);
		
		
	}

	public void addSaleItem( String...args) {
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		
		column = new PrinterBufferColumn();
		column.setScale(60);
		column.setContent(args[0]);
		column.setAlign(Printer.LEFT);
		row.columns.add(column);
		
		column = new PrinterBufferColumn();
		column.setScale(40);
		column.setContent(args[1]);
		column.setAlign(Printer.RIGHT);
		row.columns.add(column);
		
		rows.add(row);
		
	}
	
	public void addServiceItem( String...args) {
		PrinterBufferRow row = new PrinterBufferRow();
		PrinterBufferColumn column = new PrinterBufferColumn();
		
		column = new PrinterBufferColumn();
		column.setScale(20);
		column.setContent(args[0]);
		column.setAlign(Printer.LEFT);
		row.columns.add(column);
		
		column = new PrinterBufferColumn();
		column.setScale(80);
		column.setContent(args[1]);
		column.setAlign(Printer.LEFT);
		row.columns.add(column);
		
		rows.add(row);
		
	}
	
	public void addCustomRow(PrinterBufferColumn...args){
		PrinterBufferRow row = new PrinterBufferRow();
		for (int i = 0; i < args.length; i++) {
			row.columns.add(args[i]);
		}
		rows.add(row);
	}
}
